import type { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
import { currentRole } from '@/utils/role'

export const useRoleGuard = (
  to: RouteLocationNormalized,
  from: RouteLocationNormalized,
  next: NavigationGuardNext
) => {
  const role = currentRole()
  const roleArray: any = to.meta.role
  if (roleArray !== undefined && role !== null && !roleArray.includes(role)) {
    next('/404')
  } else next()
}
